package com.ahaoyou.mapper;

import com.ahaoyou.entity.HelloWorld;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description
 * @Author LH
 * @Date 2021-09-26 16:22
 */
@Repository
public interface HelloWorldMapper {

    /**
     * 查询全部
     *
     * @return HelloWorld集合
     */
    @Select("select * from hello_world")
    List<HelloWorld> findAll();

    /**
     * 批量添加
     *
     * @param list
     * @return
     */
    @Insert("<script> insert into hello_world (username,sex,arr1,arr2,arr3) values" +
            "<foreach collection='list' item='item' separator=',' > " +
            "(#{item.username},#{item.sex},#{item.arr1},#{item.arr2},#{item.arr3})" +
            " </foreach> " +
            "ON DUPLICATE KEY UPDATE" +
            "  username=values(username),sex=values(sex),arr1=values(arr1),arr2=values(arr2),arr3=values(arr3)" +
            "</script>")
    int batchInsert(List<HelloWorld> list);
}
